home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / DRIVREAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-31  |  1.8 KB  |  54 lines

  1. #include <alloc.h>
  2. #include <dos.h>
  3. #include <ctype.h>
  4. #include "tcclib.h"
  5. #include <conio.h>
  6.  
  7. #define SECTOR_SIZE 512
  8.  
  9. int DriveReady (char drv)
  10. {
  11.     int cnt, retry = 1;
  12.     union REGS inregs, outregs;
  13.     struct SREGS segregs;
  14.     unsigned char *buffer;
  15.     char back[600];
  16.  
  17.     buffer = malloc(SECTOR_SIZE);           /* allocate temp sector buffer */
  18.     cnt = 0;
  19.     while (1) {
  20.         inregs.h.ah = 0x04;                 /* function # */
  21.         inregs.h.al = 1;                    /* # of sectors */
  22.         inregs.h.ch = 0;                    /* 1st cylinder */
  23.         inregs.h.cl = 1;                    /* 1st sector */
  24.         inregs.h.dh = 0;                    /* 1st side */
  25.         inregs.h.dl = toupper(drv) - 'A';   /* drive ('A' = 0) */
  26.         segregs.es = FP_SEG(buffer);        /* ES:BX pt to buffer (for old BIOS's) */
  27.         inregs.x.bx = FP_OFF(buffer);
  28.         int86x(0x13, &inregs, &outregs, &segregs);      /* call Int 13H */
  29.  
  30.         if (!outregs.h.ah) break;           /* status ok -- return */
  31.         if (++cnt > retry) break;           /* already retried */
  32.  
  33.         /* otherwise retry -- first issue reset */
  34.         inregs.h.ah = 0x00;                 /* function # */
  35.         inregs.h.dl = toupper(drv) - 'A';   /* drive ('A' = 0) */
  36.         int86(0x13, &inregs, &outregs);     /* call Int 13H */
  37.     }
  38.  
  39.     free(buffer);
  40.  
  41.     if ( outregs.h.ah != 0 ) {
  42.         gettext( 22, 8, 57, 14, back );
  43.         BlockErase( 22, 8, 57, 14 );
  44.         ExplodeBox( 24, 9, 55, 13 );
  45.         CenterF( 11, "Drive %c is not ready ...", drv );
  46.         Center( 13, " Press any key ... " );
  47.         ChangeBlock( 24, 9, 55, 13, A_REVERSE );
  48.         GComm();
  49.         puttext( 22, 8, 57, 14, back );
  50.     }
  51.     return(!outregs.h.ah);                  /* return TRUE if drive ready */
  52. }
  53. #define SECTOR_SIZE 512
  54.